package code.class1;

import cn.hutool.core.util.ArrayUtil;

/**
 * https://leetcode.cn/problems/reverse-prefix-of-word/
 * <p>
 * 反转单词前缀
 */
public class Code10_ReversePrefix {

    public static void main(String[] args) {
        String str = "abcdefd";
        char ch = 'd';
        String res = reversePrefix(str, ch);
        System.out.println("res = " + res);
    }

    public static String reversePrefix(String word, char ch) {
        int index = word.indexOf(ch);
        char[] chars = word.toCharArray();
        int p1 = 0, p2 = index;
        while (p1 < p2) {
            ArrayUtil.swap(chars, p1++, p2--);
        }
        return new String(chars);
    }

}
